home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / gwars1.000 / gwars1 / GravityWars1.1 / tools / Converter.c < prev    next >
C/C++ Source or Header  |  1995-11-10  |  5KB  |  327 lines

  1. /*
  2.     LevelEditorData -> Level.gfx & Level.obj Converter  (C) Sami Niemi 1995
  3. */
  4.  
  5. #include<stdio.h>
  6.  
  7. FILE  *fileptr;
  8.  
  9. char filename[32];
  10.  
  11. char buf20x45[20*45];
  12.  
  13. char buf40x45[40*45];
  14.  
  15.  
  16. #define TRUE 1
  17. #define FALSE 0
  18.  
  19. void loadit() {
  20.   
  21.   char wrdy[4];
  22.   
  23.   if ( ( fileptr=fopen(filename,"r") )!=NULL) {
  24.     
  25.     do {
  26.       wrdy[0]=wrdy[1];     
  27.       wrdy[1]=wrdy[2];
  28.       wrdy[2]=wrdy[3];
  29.       wrdy[3]=fgetc(fileptr);  
  30.     } while((wrdy[0]!='S') ||
  31.         (wrdy[1]!='M') ||
  32.         (wrdy[2]!='A') || 
  33.         (wrdy[3]!='P'));
  34.     
  35.     fread(buf20x45,20*45,1,fileptr);
  36.     
  37.     fclose(fileptr);
  38.   }
  39.   else {
  40.     printf("ERROR!!!!!!!!! CAN'T LOAD THE LEVEL!\n");
  41.     exit(1);
  42.   }
  43. };
  44.  
  45.  
  46. /*
  47. char chk_S(int xx, int yy) {
  48.    
  49.   static int x,y;
  50.   static unsigned char ch;
  51.   static char bool;
  52.  
  53.   xx--; 
  54.   yy--;
  55.  
  56.   bool=FALSE;
  57.   for(y=yy; y<=(yy+2); y++) {
  58.     for(x=xx; x<=(xx+2); x++) {
  59.       ch=buf40x45[x+y*40];
  60.       if (BACKGROUND) {
  61.     bool=TRUE;
  62.     goto out;
  63.       }
  64.     }
  65.   }
  66.  out:
  67.   return bool;
  68. }
  69.     
  70. char chk_M(int xx, int yy) {
  71.  
  72.   static int x,y;
  73.   static unsigned char ch;
  74.   static char bool;
  75.  
  76.   xx-=2;
  77.   yy-=2;
  78.  
  79.   bool=FALSE;
  80.   for(y=yy; y<=(4+yy); y++) {
  81.     for(x=xx; x<=(4+xx); x++) {
  82.       ch=buf40x45[x+y*40];
  83.       if (BACKGROUND) {
  84.         bool=TRUE;
  85.         goto out;
  86.       }
  87.     }
  88.   }
  89.  out:
  90.   return bool;
  91. }
  92. */
  93.  
  94.  
  95. void procit() {
  96.  
  97.   unsigned char ch,obj;
  98.  
  99.   int x,y;
  100.  
  101.   for(y=0; y<=44; y++) {
  102.     memcpy(&buf40x45[y*40],&buf20x45[y*20],20);
  103.   }
  104.  
  105.   for(y=0; y<=44; y++) { 
  106.     for(x=0; x<=19; x++) {
  107.       
  108.       ch=buf40x45[x+y*40];
  109.       
  110.       switch(ch) {
  111.  
  112.       case 19:      /* Start Field */
  113.         obj='s';
  114.         break;
  115.  
  116.       case 28:      /* Fuel Field */
  117.         obj='f';
  118.         break;
  119.  
  120.  
  121.       case 36:      /* Background */
  122.       case 37:
  123.       case 38:
  124.     obj='.';
  125.     break;
  126.  
  127.       case 41:      /* Exit */
  128.     obj='x';
  129.     break;    
  130.  
  131.       case 51:      /* Air Key */
  132.           obj='&';
  133.     break;
  134.  
  135.       case 149:     /* Water Fuel */
  136.     obj='%';
  137.     break;
  138.  
  139.       case 209:
  140.     obj='F';  /* Extra Fuel */
  141.     break;
  142.     
  143.       case 166:
  144.       case 175:
  145.       case 184:
  146.     obj='L';  /* Extra Life */
  147.     break;
  148.  
  149.       case 162:
  150.       case 163:
  151.       case 164:
  152.       case 165:
  153.     obj='1';  /* Bonus 10 pts */
  154.     break;
  155.  
  156.       case 170:   /* Water Key */
  157.         obj='?';
  158.     break;
  159.     
  160.       case 171:     
  161.       case 172:
  162.       case 173:
  163.     obj='5';
  164.     break;
  165.  
  166.       case 174:    
  167.     obj='6';
  168.     break;
  169.  
  170.       case 180:
  171.       case 181:
  172.     obj='2';
  173.     break;
  174.  
  175.       case 182:
  176.     obj='T';  /* Extra Time */
  177.     break;
  178.  
  179.       case 183:
  180.       case 189:
  181.       case 190:
  182.     obj='4';
  183.     break;
  184.     
  185.       case 191:
  186.       case 192:
  187.       case 193:
  188.     obj='3';
  189.     break;
  190.     
  191.       case 168:     /* Destroyable Graphics (Ex. The Red Doors) */
  192.       case 176:
  193.       case 177:
  194.       case 178:
  195.       case 186:
  196.     obj='@';
  197.     break;
  198.     
  199.       case 194:     /* Water */
  200.       case 195:
  201.       case 196:
  202.       case 201:
  203.       case 202:
  204.       case 203:
  205.       case 204:
  206.       case 205:
  207.       case 210:
  208.       case 211:
  209.       case 212:
  210.       case 213:
  211.       case 214:
  212.     obj='w';
  213.     break;
  214.     
  215.       case 198:     /* Top Water */
  216.       case 199:
  217.       case 200:
  218.     obj='v';
  219.     break;
  220.  
  221.       case 179:     /* Water Bonus */  
  222.       case 206:
  223.     obj='(';
  224.     break;
  225.  
  226.       case 188:
  227.     obj=')';
  228.     break;
  229.  
  230.       case 197:
  231.     obj='[';
  232.     break;
  233.  
  234.       case 215:
  235.     obj=']';
  236.     break;
  237.  
  238.       case 123:     /* The Fan, you have to edit the wind yourself! */
  239.       case 124:
  240.       case 125:     /* Wind: QWE */
  241.       case 132:     /*       A D */
  242.       case 133:     /*       ZXC */
  243.       case 134:
  244.       case 141:
  245.       case 142:
  246.       case 143:
  247.       case 150:
  248.       case 151:
  249.       case 152:
  250.     obj='S';
  251.     break;
  252.  
  253.  
  254.       default:      /* Default */
  255.     obj='*';
  256.     break;
  257.       };
  258.     
  259.       
  260.       /* Air above the water */
  261.       if ( (y<45) && (((ch=buf40x45[x+y*40+40])>=198) && (ch<=200) ) )
  262.     obj='a';
  263.       
  264.       buf40x45[20+x+y*40]=obj;
  265.     }
  266.   }
  267. }
  268.  
  269.  
  270. void saveit() {
  271.   
  272.   int y;
  273.  
  274.   char name[64];
  275.   char author[64];
  276.  
  277.   strcpy(filename+strlen(filename),".obj");
  278.  
  279.   if ( ( fileptr=fopen(filename,"w") )!=NULL) {
  280.  
  281.     for(y=0; y<=44; y++) {
  282.       fwrite(&buf40x45[20+y*40],20,1,fileptr);
  283.       fprintf(fileptr,"--%d\n",y);
  284.     }
  285.     fprintf(fileptr,
  286.         "||||||||||||||||||||\n"
  287.         "00000000001111111111\n"
  288.         "01234567890123456789\n\n");
  289.    
  290.     fclose(fileptr);
  291.   }
  292.   else {
  293.     printf("ERROR!!!!!!!!! CAN'T SAVE THE LEVEL OBJECT DATA!\n");
  294.     exit(1);
  295.   }
  296.  
  297.   strcpy(filename+strlen(filename)-4,".gfx");
  298.  
  299.   if ( ( fileptr=fopen(filename,"w") )!=NULL) {
  300.  
  301.     for(y=0; y<=44; y++) {
  302.       fwrite(&buf40x45[y*40],20,1,fileptr);
  303.     }
  304.     fclose(fileptr);
  305.   }
  306.   else {
  307.     printf("ERROR!!!!!!!!! CAN'T SAVE THE LEVEL GFX DATA!\n");
  308.     exit(1);
  309.   }
  310.  
  311. }
  312.  
  313. main(int number, char *arg[]){
  314.  
  315.   strcpy(filename,arg[1]);
  316.   printf("\n"
  317.      "GravityWars Level Converter v0.01, Sami Niemi -95\n\n"
  318.      "Converting '%s'\n\n",filename,filename);
  319.  
  320.   loadit();
  321.   procit(); 
  322.   saveit();
  323. }
  324.  
  325.  
  326.  
  327.